<template>
  <footer class="footer">
    <span class="todo-count">剩余<strong>{{ leftCount }}</strong></span>
    <ul class="filters">
      <li>
        <a
          :class="{ selected: selectType === 'all' }"
          @click="changeType('all')"
          href="javascript:;"
        >
          全部
        </a>
      </li>
      <li>
        <a
          :class="{ selected: selectType === 'active' }"
          @click="changeType('active')"
          href="javascript:;"
        >
          未完成
        </a>
      </li>
      <li>
        <a
          :class="{ selected: selectType === 'complete' }"
          @click="changeType('complete')"
          href="javascript:;"
        >
          已完成
        </a>
      </li>
    </ul>
    <button @click="del" v-show="showClear" class="clear-completed">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  props: {
    arr: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      selectType: "all",
    };
  },
  computed: {
    // 计算未完成任务的数量
    leftCount() {
      return this.arr.filter((item) => !item.isDone).length;
    },
    // 已完成的显示隐藏
    showClear() {
        // 只要有一个没完成 结果为true 显示
      return this.arr.some((item) => item.isDone);
    },
  },
  methods: {
    // 清除已完成
    del() {
      this.$emit("clearDone");
    },
    // 点击控制高亮
    changeType(type) {
      this.selectType = type;

      this.$emit("changeType", type);
    },
  },
};
</script>
